﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Xml;
using System.Drawing;
using System.Text.RegularExpressions;

namespace ImageEditor
{
    public class MapController : Panel
    {
        private MapPanel _mapPanel;
        private String _filepath = Regex.Split(Application.ExecutablePath, "ImageEditor")[0] + "\\ImageEditor\\Images\\";

        public MapController(MapPanel mapPanel)
        {
            this._mapPanel = mapPanel;
            InitializeMapController();
        }

        private void InitializeMapController()
        {
            PictureBox leftArrow = new PictureBox();
            leftArrow.Image = Image.FromFile(_filepath + "arrowleft.png");
            leftArrow.Size = leftArrow.Image.Size;
            leftArrow.Location = new Point(42, 42);
            leftArrow.Tag = "LEFT";
            leftArrow.MouseClick += new MouseEventHandler(button_MouseClick);

            PictureBox playArrow = new PictureBox();
            playArrow.Image = Image.FromFile(_filepath + "playButton.png");
            playArrow.Size = playArrow.Image.Size;
            playArrow.Location = new Point(75, 30);
            playArrow.Tag = "PLAY";
            playArrow.MouseClick += new MouseEventHandler(button_MouseClick);

            PictureBox rightArrow = new PictureBox();
            rightArrow.Image = Image.FromFile(_filepath + "arrowright.png");
            rightArrow.Size = rightArrow.Image.Size;
            rightArrow.Location = new Point(130, 42);
            rightArrow.Tag = "RIGHT";
            rightArrow.MouseClick += new MouseEventHandler(button_MouseClick);

            this.Controls.Add(leftArrow);
            this.Controls.Add(playArrow);
            this.Controls.Add(rightArrow);

            this.Size = new Size(200, 100);
            this.Location = new Point(950, 290);
            this.BorderStyle = BorderStyle.FixedSingle;
            this.AutoScroll = true;
        }

        protected void button_MouseClick(object sender, MouseEventArgs e)
        {
            String tag = ((PictureBox)sender).Tag.ToString();
            if (!tag.Equals("PLAY"))
            {
                UpdateMap(tag);
            }
            else
            {
                _mapPanel.PlayMap();
            }
        }

        private void UpdateMap(String direction)
        {
            _mapPanel.UpdateMap(direction);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            e.Graphics.DrawString("Week Controller", new Font(FontFamily.GenericSerif, 12.0F), new SolidBrush(Color.White), new PointF(50, 10));
        }
    }
}
